﻿using System.Reactive.Linq;
using System.Windows;

using TimeSpan.Views.Pages;

namespace TimeSpan.Views.Windows;

public partial class MainWindowViewModel : ObservableObject {

    public MainWindowViewModel(INavigationService navigation, RuntimeViewModel runtimeViewModel) {
        Observable.Interval(System.TimeSpan.FromMilliseconds(100)).Subscribe(_ => Time = DateTime.Now);
        this.navigation = navigation;
        Runtime = runtimeViewModel;
    }

    private readonly INavigationService navigation;

    [ObservableProperty]
    private DateTime _time = DateTime.Now;

    public RuntimeViewModel Runtime { get; }

    [RelayCommand]
    private void Navigate(Type pageType) {
        if (pageType == typeof(HomePage) && Runtime.Task != null) {
            pageType = typeof(RuntimePage);
        }
        navigation.Navigate(pageType);
    }

    [RelayCommand]
    private static void Quit() {
        Application.Current.Shutdown();
    }

}